<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of soaUsers
 *
 * @author dxx
 */

namespace app\common\model\oms;

use think\Model;

class MemberScanBind extends Model {

    protected $base_table = 'member_scan_bind';
    protected $table = 'member_scan_bind';
    protected $connection = ['database' => 'oms'];

    public function __construct($company_id = []) {

        if (!is_array($company_id)) {
            $this->table = $this->base_table . '_' . $company_id;
        }

        parent::__construct($company_id);
    }

    /**
     * 根据usb_id获取当前记录
     * @param type $usb_id
     */
    public function getMemberScanBindByUsbId($usb_id) {
        return $this->setTable($this->table)->where(['usb_id' => $usb_id])->find();
    }

    /**
     * 更新扫码信息
     * @param type $condition
     * @param type $data
     * @return type
     */
    public function updateScanInfo($condition, $data) {
        return $this->setTable($this->table)->where($condition)->update($data);
    }

    /**
     * 查询
     * @param type $condition
     * @param type $field
     */
    public function findResultByCondition($condition, $field) {
        $result = $this->where($condition)->order('usb_id desc')->field($field)->find();
        return $result;
    }

    /**
     * 添加一个LOG
     * @param type $data
     * @return type
     */
    public function addOne($data) {
        $add = $this->data($data)->save();
        return $add->log_id;
    }

}
